<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="elementNode.js"></script>
  <script src="doubleList.js"></script>
  <script src="loopList.js"></script>

  <script>
    // 解决约瑟夫环的问题
    function ysf(total, num) {
      const loop = new LoopList();
      for (let i = 0; i < total; i++) {
        loop.insert(i + 1, i)
      }
      let delNode = loop.find(num - 1);


      while (delNode) {
        let nextNode = delNode.getNext();
        loop.remove(2)
        loop.setHead(nextNode);
        delNode = loop.find(num - 1);
      }
      return loop.toArray().map(item => item.element);
    }
  </script>
</body>

</html>